<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/public/head::head(~{::title},~{},~{})">
    <title>添加公告-饮食分析系统</title>
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form layui-form-pane" id="form" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="we-red">*</span>标题
            </label>
            <div class="layui-input-inline" style="width: 80%;">
                <input type="text" id="title"  name="title" required lay-verify="required"
                       placeholder="标题" autocomplete="off"  class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                详细内容
            </label>
            <div class="layui-input-inline" style="width: 80%;">
                <textarea id="container" name="content" style="min-height: 400px" ></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <button style="margin-left: 40%;width: 200px" class="layui-btn" lay-filter="add" lay-submit>添加</button>
        </div>
    </form>
</div>
<!-- 百度编辑器配置文件 -->
<script type="text/javascript" th:src="@{/static/common/plugs/ueditor/ueditor.config.js}"></script>
<!-- 百度编辑器编辑器源码文件 -->
<script type="text/javascript" th:src="@{/static/common/plugs/ueditor/ueditor.all.js}"></script>

<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<script type="text/javascript">
    layui.use(['form', 'layer','upload', 'jquery', 'admin'], function () {
        var form = layui.form,
            $ = layui.jquery,
            upload = layui.upload,
            layer = layui.layer;
        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data.field);
            var formData = new FormData($("#form")[0]);
            $.ajax({
                url: "/notice/add",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function(){
                    //返回的参数item，即为当前的input DOM对象
                    index = layer.load(1,{shade: [0.3,'grey']});
                },
                success: function (res) {
                    //关闭遮罩层
                    layer.close(index);
                    if (res.success == true) {
                        layer.msg(res.msg, {icon: 1, time: 1500},function () {
                            refreshParent();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1500});
                    }
                },
                error: function (res) {
                    layer.msg(res, {icon: 2, time: 1500});
                },
                complete: function () {
                }
            });
            return false;
        });
    });

</script>
</body>

</html>